#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *my_swap(char *buf, int len)
{
	if (len < 2) return;
	int s = 0, e = len-1;
	char tmp;
	while (s < e) {
		tmp = *(buf+s);
		*(buf+s) = *(buf+e);
		*(buf+e) = tmp;
		s++; e--;
	}
}
char *my_itoa(int d, char *buf)
{
	char *p = buf;
	int n = d, i = 0;
	unsigned int flag = 1;

	if (d == 0){
		*p++ = '0';
		*p = '\0';
		return buf;	
	}

	while (n && i < 32) {
		if (d&flag)
			*p++ = '1';
		else 
			*p++ = '0';
		flag <<= 1;
		n >>= 1;
		i++;
	}
	*p = '\0';
	my_swap(buf, p-buf);

	return buf;
}
void getBin(int num, char *str)
{
  *(str+5) = '\0';
  int mask = 0x10 << 1;
  while(mask >>= 1)
    *str++ = !!(mask & num) + '0';
}
void main(void)
{
	int i;
	char buf[33];
	int d[] = {0, -1345, 1345};

	for(i = 0; i < sizeof(d)/sizeof(d[0]); i++){
		//memset(buf, 0, sizeof(buf));
		my_itoa(d[i], buf);
		printf("%s\n", buf);
	}
/*	for(i = 0; i < sizeof(d)/sizeof(d[0]); i++){
		memset(buf, 0, sizeof(buf));
		my_itoa(d[i], buf, 8);
		printf("%s\n", buf);
		memset(buf, 0, sizeof(buf));
		snprintf(buf,sizeof(buf), "%o", d[i]);
		printf("%s\n", buf);
	}
	for(i = 0; i < sizeof(d)/sizeof(d[0]); i++){
		memset(buf, 0, sizeof(buf));
		my_itoa(d[i], buf, 10);
		printf("%s\n", buf);
		memset(buf, 0, sizeof(buf));
		snprintf(buf,sizeof(buf), "%d", d[i]);
		printf("%s\n", buf);
	}
	for(i = 0; i < sizeof(d)/sizeof(d[0]); i++){
		memset(buf, 0, sizeof(buf));
		my_itoa(d[i], buf, 16);
		printf("%s\n", buf);
		memset(buf, 0, sizeof(buf));
		snprintf(buf,sizeof(buf), "%x", d[i]);
		printf("%s\n", buf);
	}*/
}
